package Strategy;

import java.util.ArrayList;
import java.util.List;

/**
 * 表示农机作业路径
 */
public class Path {
    private List<Coordinate> waypoints;
    private String name;
    private double totalDistance;
    private double estimatedTime;

    // 添加无参构造函数
    public Path() {
        this.waypoints = new ArrayList<>();
        this.name = "Unnamed Path";
        this.waypoints = new ArrayList<>();

    }

    // 保留原有的构造函数
    public Path(List<Coordinate> waypoints, String name) {
        this.waypoints = waypoints;
        this.name = name;
    }

    public List<Coordinate> getWaypoints() {
        return waypoints;
    }

    public String getName() {
        return name;
    }

    // 添加方法来设置路径名称
    public void setName(String name) {
        this.name = name;
    }

    // 添加方法来添加路径点
    public void addWaypoint(Coordinate waypoint) {
        waypoints.add(waypoint);
    }

    // 添加方法来设置路径类型
    public void setPathType(String pathType) {
        this.name = pathType;
    }

    public void setWaypoints(List<Coordinate> waypoints) {
        this.waypoints = waypoints;
    }

    public double getTotalDistance() {
        return totalDistance;
    }

    public void setTotalDistance(double totalDistance) {
        this.totalDistance = totalDistance;
    }

    public double getEstimatedTime() {
        return estimatedTime;
    }

    public void setEstimatedTime(double estimatedTime) {
        this.estimatedTime = estimatedTime;
    }

    // 计算总距离的方法
    public void calculateTotalDistance() {
        double totalDistance = 0.0;
        if (waypoints.size() < 2) {
            return;
        }
        for (int i = 0; i < waypoints.size() - 1; i++) {
            totalDistance += waypoints.get(i).distanceTo(waypoints.get(i + 1));
        }
        System.out.println("路径总长度: " + totalDistance + "米");
    }

    // 计算估计时间的方法
    public void calculateEstimatedTime(double speed) {
        double totalDistance = 0.0;
        if (waypoints.size() < 2) {
            System.out.println("估计时间: 0秒");
            return;
        }
        for (int i = 0; i < waypoints.size() - 1; i++) {
            totalDistance += waypoints.get(i).distanceTo(waypoints.get(i + 1));
        }
        double timeHours = totalDistance / (speed * 3600); // 转为小时
        System.out.println("估计时间: " + timeHours + "小时");
    }

    @Override
    public String toString() {
        return name + " with " + waypoints.size() + " waypoints";
    }
}